package com.example.demo.mvvm.utils;

import com.example.demo.mvvm.bean.UserBean;

import java.util.ArrayList;

/**
 * Created by 80711 on 2018/5/23.
 */

public class UserManager {

    public static void saveUser(UserBean bean){
        AppCacheSharedPreferences.putCacheBoolean("IS_LOGIN" , true);
        AppCacheSharedPreferences.putCacheString("headIcon" , bean.getIcon());
        AppCacheSharedPreferences.putCacheString("name" , bean.getUsername());
        AppCacheSharedPreferences.putCacheString("user_id" , bean.getId() + "");
        if(bean.getCollectIds() != null && bean.getCollectIds().size() != 0){
            ArrayList<String> list = new ArrayList<>();
            for (Integer integer : bean.getCollectIds()){
                list.add(integer  + "");
            }
            AppCacheSharedPreferences.putCacheArrayList("collectIds" ,list);
        }
    }

    public static UserBean getUserBean(){
        if(AppCacheSharedPreferences.getCacheBoolean("IS_LOGIN",false)){
            UserBean userBean = new UserBean();
            userBean.setIcon(AppCacheSharedPreferences.getCacheString("headIcon"));
            userBean.setUsername(AppCacheSharedPreferences.getCacheString("name"));
            return userBean;
        }else {
            return null;
        }
    }

}
